﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VocabLib;

namespace VocabGUI
{
	public class WordsWindowViewModel
	{
		public class ViewWord : INotifyPropertyChanged
		{
			public string Hun { get; private set; }
			public string Eng { get; private set; }
			public string TotalGuessesString { get; private set; }
			public string SuccessfulGuessesString { get; private set; }
			public string PriorityString { get; private set; }

			public event PropertyChangedEventHandler PropertyChanged;

			protected virtual void OnPropertyChanged(string propertyName)
			{
				PropertyChangedEventHandler handler = PropertyChanged;
				if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
			}

			public ViewWord(VocabModel.Record r)
			{
				Hun = r.Hun;
				Eng = r.Eng;
				TotalGuessesString = "Total guesses: " + r.TotalGuesses;
				SuccessfulGuessesString = "Successful guesses: " + r.SuccessfulGuesses + " (" + r.SuccessfulGuessesInARow + " in a row)";
				PriorityString = "Priority: " + r.Priority;
			}
		}

		public List<ViewWord> Words { get; set; }
		public ObservableCollection<ViewWord> FilteredWords { get; set; }

		public WordsWindowViewModel(List<VocabModel.Record> records)
		{
			Words = new List<ViewWord>();
			records.ForEach(r => Words.Add(new ViewWord(r)));
			FilteredWords = new ObservableCollection<ViewWord>(Words);
		}
	}
}
